function createRequestObject() {
 	var httprequest;
    if(window.XMLHttpRequest) { //Mozilla, Safari...
        httprequest = new XMLHttpRequest();
        if(httprequest.overrideMimeType) {
            httprequest.overrideMimeType('text/xml');
        }
    } else if(window.ActiveXObject) {
        try {
            httprequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httprequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
	}
	return httprequest;
}

function makeRequest(url, handler) {
    var errorhandler = function() {
        alert('There was a problem with the request.');
    };
    var async = true;
    if(arguments.length == 3) {
        errorhandler = arguments[2];
    } else if(arguments.length == 4) {
    	async = arguments[3];
    }

    var httprequest = createRequestObject();
   
    if(!httprequest) {
        alert("Giving up :( Cannot create an XMLHTTP instance");
        return false;
    }

    httprequest.onreadystatechange = function() { 
        callHandler(httprequest, handler, errorhandler); 
    };
    httprequest.open('GET', url, async);
    httprequest.send('');
}

function postRequest(url, handler, paramstr) {
    var errorhandler = function() {
        alert('There was a problem with the request.');
    };
    var async = true;
    if(arguments.length == 4) {
        errorhandler = arguments[3];
    } else if(arguments.length == 5) {
    	async = arguments[4];
    }

    var httprequest = createRequestObject();
   
    if(!httprequest) {
        alert("Giving up :( Cannot create an XMLHTTP instance");
        return false;
    }

    httprequest.onreadystatechange = function() { 
        callHandler(httprequest, handler, errorhandler); 
    };
    httprequest.open('POST', url, async);
    httprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httprequest.send(paramstr);
}

function callHandler(httprequest, handler, errorhandler) {
    if(httprequest.readyState == 4) {
        if(httprequest.status == 200) {
            handler(httprequest);
        } else {
            errorhandler(httprequest);
        }
    }
}